<?php

namespace app\admin\service;

use app\common\model\AdminRole;
use app\common\model\AdminUser;
use app\common\model\AdminUserRole;
use app\common\model\Menu;
use app\Request;

use app\services\jwt\JwtService;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\facade\Config;

class MenuService
{
    protected $auth_role = [];

    function buildTree($data, $parent_id = 0)
    {
        $branch = array();
        foreach ($data as $element) {
            if ($element['pid'] == $parent_id) {
                $children = self::buildTree($data, $element['id']);
                if ($children) {
                    $element['children'] = $children;
                }
                $branch[] = $element;
            }
        }
        return $branch;
    }

    public function addMenu($data)
    {
        $menuModel = new Menu();
        $menuModel->insert($data);
       return successService([],'成功');
    }

    public function editMenu($data){
        $menuModel = new Menu();
        $menuModel->where(['id' =>$data['id']])->update($data);
        return successService([],'成功');
    }
    public function deleteMenu($data){
        $menuModel = new Menu();
        $menuModel->where(['id' =>$data['id']])->delete();
        return successService([],'成功');
    }


}